/*
 * File: Controller.cpp
 *
 * Code generated for Simulink model 'Controller'.
 *
 * Model version                  : 1.157
 * Simulink Coder version         : 8.1 (R2011b) 08-Jul-2011
 * TLC version                    : 8.1 (Jul  9 2011)
 * C/C++ source code generated on : Sat Jan 28 13:43:40 2012
 *
 * Target selection: ert.tlc
 * Embedded hardware selection: Texas Instruments->C2000
 * Code generation objectives: Unspecified
 * Validation result: Not run
 */

#include "Controller.h"
#include "Controller_private.h"

/* Named constants for Chart: '<S1>/Chart' */
#define Controller_IN_Duty             (1U)
#define Controller_IN_Fail             (2U)
#define Controller_IN_Init             (3U)
#define Controller_IN_NO_ACTIVE_CHILD  (0U)
#define Controller_IN_OFF              (1U)
#define Controller_IN_On               (2U)
#define Controller_IN_Position         (4U)
#define Controller_IN_Speed            (5U)
#define Controller_IN_Torque           (6U)

/* Model step function */
void ControllerModelClass::step()
{
  real32_T rtb_Sum3;
  real32_T rtb_IntegralGain_a;
  boolean_T rtb_NotEqual_n;
  real32_T rtb_SignPreSat_f;

  /* Outputs for Atomic SubSystem: '<Root>/Controller' */
  /* Chart: '<S1>/Chart' incorporates:
   *  Inport: '<Root>/Locked'
   *  Inport: '<Root>/Mode'
   */
  Controller_DWork.presentTicks = Controller_M->Timing.clockTick0;
  Controller_DWork.elapsedTicks = Controller_DWork.presentTicks -
    Controller_DWork.previousTicks;
  Controller_DWork.previousTicks = Controller_DWork.presentTicks;
  if ((uint32_T)Controller_DWork.temporalCounter_i1 +
      Controller_DWork.elapsedTicks <= 65535UL) {
    Controller_DWork.temporalCounter_i1 = (uint16_T)((uint32_T)
      Controller_DWork.temporalCounter_i1 + Controller_DWork.elapsedTicks);
  } else {
    Controller_DWork.temporalCounter_i1 = MAX_uint16_T;
  }

  /* Gateway: Controller/Chart */
  /* During: Controller/Chart */
  if ((uint16_T)Controller_DWork.is_active_c1_Controller == 0U) {
    /* Entry: Controller/Chart */
    Controller_DWork.is_active_c1_Controller = 1U;

    /* Transition: '<S2>:43' */
    Controller_DWork.is_c1_Controller = Controller_IN_OFF;

    /* Entry 'OFF': '<S2>:1' */
    Controller_B.Enable = 0L;
    Controller_B.CurrPID = 0L;
    Controller_B.SpeedPID = 0L;
    Controller_B.SpOverride = 0L;
    Controller_B.PosPID = 0L;
    Controller_B.State = 0L;
  } else {
    switch (Controller_DWork.is_c1_Controller) {
     case Controller_IN_OFF:
      /* During 'OFF': '<S2>:1' */
      if (Controller_U.Mode != 0L) {
        /* Transition: '<S2>:13' */
        Controller_DWork.is_c1_Controller = Controller_IN_On;

        /* Transition: '<S2>:16' */
        Controller_DWork.is_On = Controller_IN_Duty;

        /* Entry 'Duty': '<S2>:2' */
        Controller_B.Enable = 1L;
        Controller_B.CurrPID = 0L;
        Controller_B.SpeedPID = 0L;
        Controller_B.SpOverride = 0L;
        Controller_B.PosPID = 0L;
        Controller_B.State = 1L;
      }
      break;

     case Controller_IN_On:
      /* During 'On': '<S2>:7' */
      if (Controller_U.Mode == 0L) {
        /* Transition: '<S2>:15' */
        Controller_DWork.is_On = Controller_IN_NO_ACTIVE_CHILD;
        Controller_DWork.is_c1_Controller = Controller_IN_OFF;

        /* Entry 'OFF': '<S2>:1' */
        Controller_B.Enable = 0L;
        Controller_B.CurrPID = 0L;
        Controller_B.SpeedPID = 0L;
        Controller_B.SpOverride = 0L;
        Controller_B.PosPID = 0L;
        Controller_B.State = 0L;
      } else {
        switch (Controller_DWork.is_On) {
         case Controller_IN_Duty:
          /* During 'Duty': '<S2>:2' */
          if (Controller_U.Mode == 2L) {
            /* Transition: '<S2>:17' */
            Controller_DWork.is_On = Controller_IN_Torque;

            /* Entry 'Torque': '<S2>:3' */
            Controller_B.CurrPID = 1L;
            Controller_B.State = 2L;
          } else if (Controller_U.Mode == 3L) {
            /* Transition: '<S2>:18' */
            Controller_DWork.is_On = Controller_IN_Speed;

            /* Entry 'Speed': '<S2>:4' */
            Controller_B.CurrPID = 1L;
            Controller_B.SpeedPID = 1L;
            Controller_B.State = 3L;
          } else {
            if (Controller_U.Mode == 4L) {
              /* Transition: '<S2>:19' */
              Controller_DWork.is_On = Controller_IN_Init;
              Controller_DWork.temporalCounter_i1 = 0U;

              /* Entry 'Init': '<S2>:5' */
              Controller_B.CurrPID = 1L;
              Controller_B.SpeedPID = 1L;
              Controller_B.SpOverride = 1L;
            }
          }
          break;

         case Controller_IN_Fail:
          break;

         case Controller_IN_Init:
          /* During 'Init': '<S2>:5' */
          if (Controller_U.Locked != 0L) {
            /* Transition: '<S2>:21' */
            Controller_DWork.is_On = Controller_IN_Position;

            /* Entry 'Position': '<S2>:6' */
            Controller_B.SpOverride = 0L;
            Controller_B.PosPID = 1L;
            Controller_B.State = 4L;
          } else {
            if (Controller_DWork.temporalCounter_i1 >= 60000U) {
              /* Transition: '<S2>:33' */
              Controller_DWork.is_On = Controller_IN_Fail;

              /* Entry 'Fail': '<S2>:32' */
              Controller_B.Enable = 0L;
              Controller_B.State = 10L;
            }
          }
          break;

         case Controller_IN_Position:
          break;

         case Controller_IN_Speed:
          break;

         case Controller_IN_Torque:
          break;

         default:
          /* Transition: '<S2>:16' */
          Controller_DWork.is_On = Controller_IN_Duty;

          /* Entry 'Duty': '<S2>:2' */
          Controller_B.Enable = 1L;
          Controller_B.CurrPID = 0L;
          Controller_B.SpeedPID = 0L;
          Controller_B.SpOverride = 0L;
          Controller_B.PosPID = 0L;
          Controller_B.State = 1L;
          break;
        }
      }
      break;

     default:
      /* Transition: '<S2>:43' */
      Controller_DWork.is_c1_Controller = Controller_IN_OFF;

      /* Entry 'OFF': '<S2>:1' */
      Controller_B.Enable = 0L;
      Controller_B.CurrPID = 0L;
      Controller_B.SpeedPID = 0L;
      Controller_B.SpOverride = 0L;
      Controller_B.PosPID = 0L;
      Controller_B.State = 0L;
      break;
    }
  }

  /* End of Chart: '<S1>/Chart' */

  /* Sum: '<S1>/Sum3' incorporates:
   *  Inport: '<Root>/InRef'
   *  Inport: '<Root>/PositionN'
   *  Saturate: '<S1>/PosLimiter'
   */
  rtb_Sum3 = (Controller_U.InRef >= Controller_P.PosLimiter_UpperSat ?
              Controller_P.PosLimiter_UpperSat : Controller_U.InRef <=
              Controller_P.PosLimiter_LowerSat ?
              Controller_P.PosLimiter_LowerSat : Controller_U.InRef) -
    Controller_U.PositionN;

  /* Outputs for Enabled SubSystem: '<S1>/PositionCtrl' incorporates:
   *  EnablePort: '<S4>/Enable'
   */
  if (Controller_B.PosPID > 0L) {
    if (!Controller_DWork.PositionCtrl_MODE) {
      /* InitializeConditions for DiscreteIntegrator: '<S9>/Integrator' */
      Controller_DWork.Integrator_DSTATE_p = Controller_P.Integrator_IC_k;
      Controller_DWork.PositionCtrl_MODE = TRUE;
    }

    /* Sum: '<S9>/Sum' incorporates:
     *  DiscreteIntegrator: '<S9>/Integrator'
     *  Gain: '<S9>/Proportional Gain'
     */
    rtb_IntegralGain_a = Controller_P.ProportionalGain_Gain_c * rtb_Sum3 +
      Controller_DWork.Integrator_DSTATE_p;

    /* Saturate: '<S9>/Saturation' */
    Controller_B.Saturation_g = rtb_IntegralGain_a >=
      Controller_P.Saturation_UpperSat_e ? Controller_P.Saturation_UpperSat_e :
      rtb_IntegralGain_a <= Controller_P.Saturation_LowerSat_j ?
      Controller_P.Saturation_LowerSat_j : rtb_IntegralGain_a;

    /* RelationalOperator: '<S10>/NotEqual' */
    rtb_NotEqual_n = (rtb_IntegralGain_a != Controller_B.Saturation_g);

    /* Signum: '<S10>/SignPreSat' */
    rtb_SignPreSat_f = rtb_IntegralGain_a < 0.0F ? -1.0F : rtb_IntegralGain_a >
      0.0F ? 1.0F : rtb_IntegralGain_a == 0.0F ? 0.0F : rtb_IntegralGain_a;

    /* Gain: '<S9>/Integral Gain' */
    rtb_IntegralGain_a = Controller_P.IntegralGain_Gain_e * rtb_Sum3;

    /* Switch: '<S9>/Switch' incorporates:
     *  Constant: '<S9>/Constant'
     *  Logic: '<S10>/AND'
     *  RelationalOperator: '<S10>/Equal'
     *  Signum: '<S10>/SignPreIntegrator'
     */
    if (rtb_NotEqual_n && ((rtb_IntegralGain_a < 0.0F ? -1.0F :
                            rtb_IntegralGain_a > 0.0F ? 1.0F :
                            rtb_IntegralGain_a == 0.0F ? 0.0F :
                            rtb_IntegralGain_a) == rtb_SignPreSat_f)) {
      rtb_IntegralGain_a = Controller_P.Constant_Value_k;
    }

    /* End of Switch: '<S9>/Switch' */

    /* Update for DiscreteIntegrator: '<S9>/Integrator' */
    Controller_DWork.Integrator_DSTATE_p = Controller_P.Integrator_gainval_a *
      rtb_IntegralGain_a + Controller_DWork.Integrator_DSTATE_p;
  } else {
    if (Controller_DWork.PositionCtrl_MODE) {
      /* Disable for Outport: '<S4>/Out1' */
      Controller_B.Saturation_g = Controller_P.Out1_Y0_d;
      Controller_DWork.PositionCtrl_MODE = FALSE;
    }
  }

  /* End of Outputs for SubSystem: '<S1>/PositionCtrl' */

  /* Switch: '<S1>/Switch' incorporates:
   *  Constant: '<S1>/Constant'
   *  Inport: '<Root>/InRef'
   *  Switch: '<S1>/Switch3'
   */
  if (Controller_B.SpOverride != 0L) {
    rtb_Sum3 = Controller_P.Constant_Value;
  } else if (Controller_B.PosPID != 0L) {
    /* Switch: '<S1>/Switch3' */
    rtb_Sum3 = Controller_B.Saturation_g;
  } else {
    rtb_Sum3 = Controller_U.InRef;
  }

  /* End of Switch: '<S1>/Switch' */

  /* Sum: '<S1>/Sum2' incorporates:
   *  Inport: '<Root>/OmegaRadS'
   */
  rtb_Sum3 -= Controller_U.OmegaRadS;

  /* Outputs for Enabled SubSystem: '<S1>/SpeedCtrl' incorporates:
   *  EnablePort: '<S5>/Enable'
   */
  if (Controller_B.SpeedPID > 0L) {
    if (!Controller_DWork.SpeedCtrl_MODE) {
      /* InitializeConditions for DiscreteIntegrator: '<S11>/Integrator' */
      Controller_DWork.Integrator_DSTATE = Controller_P.Integrator_IC_j;

      /* InitializeConditions for DiscreteIntegrator: '<S11>/Filter' */
      Controller_DWork.Filter_DSTATE = Controller_P.Filter_IC;
      Controller_DWork.SpeedCtrl_MODE = TRUE;
    }

    /* Gain: '<S11>/Filter Coefficient' incorporates:
     *  DiscreteIntegrator: '<S11>/Filter'
     *  Gain: '<S11>/Derivative Gain'
     *  Sum: '<S11>/SumD'
     */
    rtb_IntegralGain_a = (Controller_P.DerivativeGain_Gain * rtb_Sum3 -
                          Controller_DWork.Filter_DSTATE) *
      Controller_P.FilterCoefficient_Gain;

    /* Sum: '<S11>/Sum' incorporates:
     *  DiscreteIntegrator: '<S11>/Integrator'
     *  Gain: '<S11>/Proportional Gain'
     */
    rtb_SignPreSat_f = (Controller_P.ProportionalGain_Gain_ca * rtb_Sum3 +
                        Controller_DWork.Integrator_DSTATE) + rtb_IntegralGain_a;

    /* Saturate: '<S11>/Saturation' */
    Controller_B.Saturation = rtb_SignPreSat_f >=
      Controller_P.Saturation_UpperSat_ef ? Controller_P.Saturation_UpperSat_ef :
      rtb_SignPreSat_f <= Controller_P.Saturation_LowerSat_k ?
      Controller_P.Saturation_LowerSat_k : rtb_SignPreSat_f;

    /* Gain: '<S11>/Integral Gain' */
    rtb_Sum3 *= Controller_P.IntegralGain_Gain_a;

    /* Switch: '<S11>/Switch' incorporates:
     *  Constant: '<S11>/Constant'
     *  Logic: '<S12>/AND'
     *  RelationalOperator: '<S12>/Equal'
     *  RelationalOperator: '<S12>/NotEqual'
     *  Signum: '<S12>/SignPreIntegrator'
     *  Signum: '<S12>/SignPreSat'
     */
    if ((rtb_SignPreSat_f != Controller_B.Saturation) && ((rtb_SignPreSat_f <
          0.0F ? -1.0F : rtb_SignPreSat_f > 0.0F ? 1.0F : rtb_SignPreSat_f ==
          0.0F ? 0.0F : rtb_SignPreSat_f) == (rtb_Sum3 < 0.0F ? -1.0F : rtb_Sum3
          > 0.0F ? 1.0F : rtb_Sum3 == 0.0F ? 0.0F : rtb_Sum3))) {
      rtb_Sum3 = Controller_P.Constant_Value_g;
    }

    /* End of Switch: '<S11>/Switch' */

    /* Update for DiscreteIntegrator: '<S11>/Integrator' */
    Controller_DWork.Integrator_DSTATE = Controller_P.Integrator_gainval_f *
      rtb_Sum3 + Controller_DWork.Integrator_DSTATE;

    /* Update for DiscreteIntegrator: '<S11>/Filter' */
    Controller_DWork.Filter_DSTATE = Controller_P.Filter_gainval *
      rtb_IntegralGain_a + Controller_DWork.Filter_DSTATE;
  } else {
    if (Controller_DWork.SpeedCtrl_MODE) {
      /* Disable for Outport: '<S5>/Out1' */
      Controller_B.Saturation = Controller_P.Out1_Y0_du;
      Controller_DWork.SpeedCtrl_MODE = FALSE;
    }
  }

  /* End of Outputs for SubSystem: '<S1>/SpeedCtrl' */

  /* Switch: '<S1>/Switch2' incorporates:
   *  Inport: '<Root>/InRef'
   */
  if (Controller_B.SpeedPID != 0L) {
    rtb_Sum3 = Controller_B.Saturation;
  } else {
    rtb_Sum3 = Controller_U.InRef;
  }

  /* End of Switch: '<S1>/Switch2' */

  /* Switch: '<S6>/Switch4' */
  if (Controller_B.SpOverride != 0L) {
    /* Saturate: '<S6>/0.8A Limit' */
    rtb_Sum3 = rtb_Sum3 >= Controller_P.uALimit_UpperSat ?
      Controller_P.uALimit_UpperSat : rtb_Sum3 <= Controller_P.uALimit_LowerSat ?
      Controller_P.uALimit_LowerSat : rtb_Sum3;
  } else {
    /* Saturate: '<S6>/3A Limit' */
    rtb_Sum3 = rtb_Sum3 >= Controller_P.ALimit_UpperSat ?
      Controller_P.ALimit_UpperSat : rtb_Sum3 <= Controller_P.ALimit_LowerSat ?
      Controller_P.ALimit_LowerSat : rtb_Sum3;
  }

  /* End of Switch: '<S6>/Switch4' */

  /* Sum: '<S1>/Sum1' incorporates:
   *  Inport: '<Root>/CurrentU'
   */
  rtb_Sum3 -= Controller_U.Iscaled;

  /* Outputs for Enabled SubSystem: '<S1>/CurrentCtrl' incorporates:
   *  EnablePort: '<S3>/Enable'
   */
  if (Controller_B.CurrPID > 0L) {
    if (!Controller_DWork.CurrentCtrl_MODE) {
      /* InitializeConditions for DiscreteIntegrator: '<S7>/Integrator' */
      Controller_DWork.Integrator_DSTATE_f = Controller_P.Integrator_IC;
      Controller_DWork.CurrentCtrl_MODE = TRUE;
    }

    /* Sum: '<S7>/Sum' incorporates:
     *  DiscreteIntegrator: '<S7>/Integrator'
     *  Gain: '<S7>/Proportional Gain'
     */
    rtb_IntegralGain_a = Controller_P.ProportionalGain_Gain * rtb_Sum3 +
      Controller_DWork.Integrator_DSTATE_f;

    /* Saturate: '<S7>/Saturation' */
    Controller_B.Saturation_i = rtb_IntegralGain_a >=
      Controller_P.Saturation_UpperSat ? Controller_P.Saturation_UpperSat :
      rtb_IntegralGain_a <= Controller_P.Saturation_LowerSat ?
      Controller_P.Saturation_LowerSat : rtb_IntegralGain_a;

    /* RelationalOperator: '<S8>/NotEqual' */
    rtb_NotEqual_n = (rtb_IntegralGain_a != Controller_B.Saturation_i);

    /* Signum: '<S8>/SignPreSat' */
    rtb_SignPreSat_f = rtb_IntegralGain_a < 0.0F ? -1.0F : rtb_IntegralGain_a >
      0.0F ? 1.0F : rtb_IntegralGain_a == 0.0F ? 0.0F : rtb_IntegralGain_a;

    /* Gain: '<S7>/Integral Gain' */
    rtb_IntegralGain_a = Controller_P.IntegralGain_Gain * rtb_Sum3;

    /* Switch: '<S7>/Switch' incorporates:
     *  Constant: '<S7>/Constant'
     *  Logic: '<S8>/AND'
     *  RelationalOperator: '<S8>/Equal'
     *  Signum: '<S8>/SignPreIntegrator'
     */
    if (rtb_NotEqual_n && ((rtb_IntegralGain_a < 0.0F ? -1.0F :
                            rtb_IntegralGain_a > 0.0F ? 1.0F :
                            rtb_IntegralGain_a == 0.0F ? 0.0F :
                            rtb_IntegralGain_a) == rtb_SignPreSat_f)) {
      rtb_IntegralGain_a = Controller_P.Constant_Value_f;
    }

    /* End of Switch: '<S7>/Switch' */

    /* Update for DiscreteIntegrator: '<S7>/Integrator' */
    Controller_DWork.Integrator_DSTATE_f = Controller_P.Integrator_gainval *
      rtb_IntegralGain_a + Controller_DWork.Integrator_DSTATE_f;
  } else {
    if (Controller_DWork.CurrentCtrl_MODE) {
      /* Disable for Outport: '<S3>/Out1' */
      Controller_B.Saturation_i = Controller_P.Out1_Y0;
      Controller_DWork.CurrentCtrl_MODE = FALSE;
    }
  }

  /* End of Outputs for SubSystem: '<S1>/CurrentCtrl' */

  /* Switch: '<S1>/Switch1' */
  if (Controller_B.CurrPID != 0L) {
    /* Outport: '<Root>/DutyU' */
    Controller_Y.DutyU = Controller_B.Saturation_i;
  } else {
    /* Outport: '<Root>/DutyU' incorporates:
     *  Inport: '<Root>/InRef'
     */
    Controller_Y.DutyU = Controller_U.InRef;
  }

  /* End of Switch: '<S1>/Switch1' */
  /* End of Outputs for SubSystem: '<Root>/Controller' */

  /* Outport: '<Root>/Enable' */
  Controller_Y.Enable = Controller_B.Enable;

  /* Outport: '<Root>/State' */
  Controller_Y.State = Controller_B.State;

  /* Update absolute time for base rate */
  /* The "clockTick0" counts the number of times the code of this task has
   * been executed. The resolution of this integer timer is 0.0001, which is the step size
   * of the task. Size of "clockTick0" ensures timer will not overflow during the
   * application lifespan selected.
   * Timer of this task consists of two 32 bit unsigned integers.
   * The two integers represent the low bits Timing.clockTick0 and the high bits
   * Timing.clockTickH0. When the low bit overflows to 0, the high bits increment.
   */
  Controller_M->Timing.clockTick0++;
  if (!Controller_M->Timing.clockTick0) {
    Controller_M->Timing.clockTickH0++;
  }
}

/* Model initialize function */
void ControllerModelClass::initialize()
{
  /* Registration code */

  /* initialize real-time model */
  (void) memset((void *)Controller_M, 0,
                sizeof(RT_MODEL_Controller));

  /* block I/O */
  (void) memset(((void *) &Controller_B), 0,
                sizeof(BlockIO_Controller));

  /* states (dwork) */
  (void) memset((void *)&Controller_DWork, 0,
                sizeof(D_Work_Controller));

  /* external inputs */
  (void) memset((void *)&Controller_U, 0,
                sizeof(ExternalInputs_Controller));

  /* external outputs */
  (void) memset((void *)&Controller_Y, 0,
                sizeof(ExternalOutputs_Controller));

  /* Start for Atomic SubSystem: '<Root>/Controller' */
  /* Start for Enabled SubSystem: '<S1>/PositionCtrl' */
  /* InitializeConditions for DiscreteIntegrator: '<S9>/Integrator' */
  Controller_DWork.Integrator_DSTATE_p = Controller_P.Integrator_IC_k;

  /* VirtualOutportStart for Outport: '<S4>/Out1' */
  Controller_B.Saturation_g = Controller_P.Out1_Y0_d;

  /* End of Start for SubSystem: '<S1>/PositionCtrl' */

  /* Start for Enabled SubSystem: '<S1>/SpeedCtrl' */
  /* InitializeConditions for DiscreteIntegrator: '<S11>/Integrator' */
  Controller_DWork.Integrator_DSTATE = Controller_P.Integrator_IC_j;

  /* InitializeConditions for DiscreteIntegrator: '<S11>/Filter' */
  Controller_DWork.Filter_DSTATE = Controller_P.Filter_IC;

  /* VirtualOutportStart for Outport: '<S5>/Out1' */
  Controller_B.Saturation = Controller_P.Out1_Y0_du;

  /* End of Start for SubSystem: '<S1>/SpeedCtrl' */

  /* Start for Enabled SubSystem: '<S1>/CurrentCtrl' */
  /* InitializeConditions for DiscreteIntegrator: '<S7>/Integrator' */
  Controller_DWork.Integrator_DSTATE_f = Controller_P.Integrator_IC;

  /* VirtualOutportStart for Outport: '<S3>/Out1' */
  Controller_B.Saturation_i = Controller_P.Out1_Y0;

  /* End of Start for SubSystem: '<S1>/CurrentCtrl' */
  /* End of Start for SubSystem: '<Root>/Controller' */

  /* Start for Outport: '<Root>/Enable' */
  Controller_Y.Enable = Controller_B.Enable;

  /* Start for Outport: '<Root>/State' */
  Controller_Y.State = Controller_B.State;

  /* InitializeConditions for Atomic SubSystem: '<Root>/Controller' */
  /* InitializeConditions for Chart: '<S1>/Chart' */
  Controller_DWork.is_On = 0U;
  Controller_DWork.is_active_c1_Controller = 0U;
  Controller_DWork.is_c1_Controller = 0U;
  Controller_B.PosPID = 0L;
  Controller_B.SpeedPID = 0L;
  Controller_B.CurrPID = 0L;
  Controller_B.SpOverride = 0L;
  Controller_B.Enable = 0L;
  Controller_B.State = 0L;
  Controller_DWork.presentTicks = 0UL;
  Controller_DWork.elapsedTicks = 0UL;
  Controller_DWork.previousTicks = 0UL;

  /* End of InitializeConditions for SubSystem: '<Root>/Controller' */

  /* Enable for Atomic SubSystem: '<Root>/Controller' */
  /* Enable for Chart: '<S1>/Chart' */
  Controller_DWork.presentTicks = Controller_M->Timing.clockTick0;
  Controller_DWork.previousTicks = Controller_DWork.presentTicks;

  /* End of Enable for SubSystem: '<Root>/Controller' */
}

/* Model terminate function */
void ControllerModelClass::terminate()
{
  /* (no terminate code required) */
}

/* Constructor */
ControllerModelClass::ControllerModelClass()
{
  Parameters_Controller Controller_P_temp = {
    -60.0F,                            /* Computed Parameter: Constant_Value
                                        * Referenced by: '<S1>/Constant'
                                        */
    0.0F,                              /* Computed Parameter: Out1_Y0
                                        * Referenced by: '<S3>/Out1'
                                        */
    1.0F,                              /* Computed Parameter: ProportionalGain_Gain
                                        * Referenced by: '<S7>/Proportional Gain'
                                        */
    0.0001F,                           /* Computed Parameter: Integrator_gainval
                                        * Referenced by: '<S7>/Integrator'
                                        */
    0.0F,                              /* Computed Parameter: Integrator_IC
                                        * Referenced by: '<S7>/Integrator'
                                        */
    0.5F,                              /* Computed Parameter: Saturation_UpperSat
                                        * Referenced by: '<S7>/Saturation'
                                        */
    -0.5F,                             /* Computed Parameter: Saturation_LowerSat
                                        * Referenced by: '<S7>/Saturation'
                                        */
    5000.0F,                           /* Computed Parameter: IntegralGain_Gain
                                        * Referenced by: '<S7>/Integral Gain'
                                        */
    0.0F,                              /* Computed Parameter: Constant_Value_f
                                        * Referenced by: '<S7>/Constant'
                                        */
    0.0F,                              /* Computed Parameter: Out1_Y0_d
                                        * Referenced by: '<S4>/Out1'
                                        */
    1.0F,                              /* Computed Parameter: ProportionalGain_Gain_c
                                        * Referenced by: '<S9>/Proportional Gain'
                                        */
    0.0001F,                           /* Computed Parameter: Integrator_gainval_a
                                        * Referenced by: '<S9>/Integrator'
                                        */
    0.0F,                              /* Computed Parameter: Integrator_IC_k
                                        * Referenced by: '<S9>/Integrator'
                                        */
    500.0F,                            /* Computed Parameter: Saturation_UpperSat_e
                                        * Referenced by: '<S9>/Saturation'
                                        */
    -500.0F,                           /* Computed Parameter: Saturation_LowerSat_j
                                        * Referenced by: '<S9>/Saturation'
                                        */
    0.0F,                              /* Computed Parameter: IntegralGain_Gain_e
                                        * Referenced by: '<S9>/Integral Gain'
                                        */
    0.0F,                              /* Computed Parameter: Constant_Value_k
                                        * Referenced by: '<S9>/Constant'
                                        */
    0.0F,                              /* Computed Parameter: Out1_Y0_du
                                        * Referenced by: '<S5>/Out1'
                                        */
    0.002F,                            /* Computed Parameter: ProportionalGain_Gain_ca
                                        * Referenced by: '<S11>/Proportional Gain'
                                        */
    0.0001F,                           /* Computed Parameter: Integrator_gainval_f
                                        * Referenced by: '<S11>/Integrator'
                                        */
    0.0F,                              /* Computed Parameter: Integrator_IC_j
                                        * Referenced by: '<S11>/Integrator'
                                        */
    0.0F,                              /* Computed Parameter: DerivativeGain_Gain
                                        * Referenced by: '<S11>/Derivative Gain'
                                        */
    0.0001F,                           /* Computed Parameter: Filter_gainval
                                        * Referenced by: '<S11>/Filter'
                                        */
    0.0F,                              /* Computed Parameter: Filter_IC
                                        * Referenced by: '<S11>/Filter'
                                        */
    10.0F,                             /* Computed Parameter: FilterCoefficient_Gain
                                        * Referenced by: '<S11>/Filter Coefficient'
                                        */
    0.2F,                              /* Computed Parameter: Saturation_UpperSat_ef
                                        * Referenced by: '<S11>/Saturation'
                                        */
    -0.2F,                             /* Computed Parameter: Saturation_LowerSat_k
                                        * Referenced by: '<S11>/Saturation'
                                        */
    0.0F,                              /* Computed Parameter: IntegralGain_Gain_a
                                        * Referenced by: '<S11>/Integral Gain'
                                        */
    0.0F,                              /* Computed Parameter: Constant_Value_g
                                        * Referenced by: '<S11>/Constant'
                                        */
    0.3F,                              /* Computed Parameter: ALimit_UpperSat
                                        * Referenced by: '<S6>/3A Limit'
                                        */
    -0.3F,                             /* Computed Parameter: ALimit_LowerSat
                                        * Referenced by: '<S6>/3A Limit'
                                        */
    0.08F,                             /* Computed Parameter: uALimit_UpperSat
                                        * Referenced by: '<S6>/0.8A Limit'
                                        */
    -0.08F,                            /* Computed Parameter: uALimit_LowerSat
                                        * Referenced by: '<S6>/0.8A Limit'
                                        */
    3800.0F,                           /* Computed Parameter: PosLimiter_UpperSat
                                        * Referenced by: '<S1>/PosLimiter'
                                        */
    0.0F                               /* Computed Parameter: PosLimiter_LowerSat
                                        * Referenced by: '<S1>/PosLimiter'
                                        */
  };                                   /* Modifiable parameters */

  /* Initialize tunable parameters */
  Controller_P = Controller_P_temp;

  /* Real-Time Model */
  Controller_M = &Controller_M_;
}

/* Destructor */
ControllerModelClass::~ControllerModelClass()
{
  /* Currently there is no destructor body generated.*/
}

/* Real-Time Model get method */
RT_MODEL_Controller * ControllerModelClass::getRTM() const
{
  return Controller_M;
}

/*
 * File trailer for generated code.
 *
 * [EOF]
 */
